#ifndef ADDMQTTDIALOG_H
#define ADDMQTTDIALOG_H

#include <QDialog>

namespace Ui {
class AddMqttDialog;
}

class MqttData //mqtt控件数据类型
{
public:
    enum eType
    {
        eSwitch = 0,    //开关量
        eAnalog,        //模拟量
        eText           //文本量
    };
    QString topic = "";
    int type = eAnalog;  //默认为模拟量
    bool publish = 0;
    int qos = 0;
    QByteArray data;
    //下面重载操作符不可使得类不可继承QObject类（继承QObject后它不允许对象的赋值操作）
    friend QDataStream &operator<<(QDataStream &stream, const MqttData &d)
    {
        stream << d.topic<<d.type<<d.publish<<d.qos<<d.data;
        return stream;
    }
    friend QDataStream &operator>>(QDataStream &stream, MqttData &d)
    {
        stream >> d.topic>>d.type>>d.publish>>d.qos>>d.data;
        return stream;
    }
};
class AddMqttDialog : public QDialog
{
    Q_OBJECT

public:
    explicit AddMqttDialog(QString title,QWidget *parent = nullptr);
    explicit AddMqttDialog(QString title,MqttData data,QWidget *parent = nullptr);
    ~AddMqttDialog();
    void setData(MqttData data);
    MqttData getData();

private:
    Ui::AddMqttDialog *ui;
};

#endif // ADDMQTTDIALOG_H
